import type {CommandRegistryItem, CommandHandler} from './command.type'



// 注册项工厂类
export class RegistryItemFactory {
  static create(module: string, type: 'ui' | 'service', name: string, handler: CommandHandler, context?: Record<string, any>): CommandRegistryItem {
    if (context !== undefined) {
      return { moduleName: module, type, commandName: name, handler, context: context};
    }
    return { moduleName: module, type, commandName: name, handler };
  }

  static forService(module: string, name: string, handler: CommandHandler, context?: Record<string, any>): CommandRegistryItem {
    return RegistryItemFactory.create(module, 'service', name, handler, context);
  }

  static forUi(module: string, name: string, handler: CommandHandler, context?: Record<string, any>): CommandRegistryItem {
    return RegistryItemFactory.create(module, 'ui', name, handler, context);
  }
}